/* 
使用格式:
    1.引入公用样式表
    2.引入当前样式表
    3.引入公用js模块
    4.具体功能

*/
require("../../assets/css/property.less")

// 1.引入公用样式表
require("../../assets/css/index.less");

let https = require("../../utils/https.js")

//引入swiper
import Swiper, { Autoplay, Pagination } from "swiper"
import "swiper/swiper-bundle.css"
// 2.引入当前样式表
require("./home.less");
// let Swiper = require("../../assets/lib/swiper/swiper.js");
require("../../assets/lib/swiper/swiper.css");
require("../../assets/fonts/iconfont.css");
// 3.引入公用js模块
let dom = require("../../utils/dom.js");
// let http = require('../../utils/http.js');
// 4.具体功能
//获取当前页面中的单个节点
// console.log(dom.getEle('h1'));
//获取当前页面中的多个节点
// console.log(dom.getEles('h1'));









dom.isLogin()

dom.ready(function () {

	dom.contFooter("home")
	Swiper.use([Autoplay, Pagination])

	new Swiper(".swiper-container", {
		loop: true, // 允许图片循环
		pagination: {
			// 显示轮播分页
			el: ".swiper-pagination",
		},
		autoplay: true, // 自动播放
	});


	function gitUser() {
		https.get("/api/user/info", res => {

			if (res.errno === 0) {


				//解构赋值

				let { ranking, badges } = res.data

				dom.getEle(".rank").textContent = ranking

				dom.getEle(".badges").textContent = badges
			}
		})
	}

	gitUser()

	//获取打卡信息
	function gitClock() {
		https.get("/api/user/clockInInfo", res => {
			dom.getEle(".clock").textContent = res.data.isClockIn ? "以打卡" : "今日打卡"
			dom.getEle(".day").textContent = res.data.clockCount
		})

	}

	gitClock()

	//点击打卡

	dom.getEle(".clock").addEventListener("click", function () {

		https.post("/api/user/clockIn", {}, res => {
			if (res.errno === 0) {
				alert("打卡成功")
				gitClock()

			} else {
				alert(res.message)
			}
		})

	})





});










